package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/10/26 15:10
 */
public class MaxProfitTest {

    public static void main(String[] args) {

    }

    public int maxProfit(int[] prices) {
        if (prices.length == 0) {
            return 0;
        }
        int minPrice = prices[0];
        int maxPrice = 0;
        for (int price : prices) {
            if (price < minPrice) {
                minPrice = price;
            } else {
                if (price - minPrice > maxPrice) {
                    maxPrice = price - minPrice;
                }
            }
        }
        return maxPrice;
    }
}
